package com.falm.picturebackend.util;

import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Map;

import org.yaml.snakeyaml.Yaml;

public class YamlConfigUtil {
    private static Map<String, Object> config;

    static {
        try (InputStream in = Files.newInputStream(Paths.get("D:\\MyCode\\picture\\picture-backend\\src\\main\\resources\\application.yaml"))) {
            config = new Yaml().load(in);
        } catch (Exception e) {
            throw new RuntimeException("Failed to load YAML config", e);
        }
    }

    public static Object getConfig(String path) {
        String[] keys = path.split("\\.");
        Map<String, Object> current = config;
        
        for (int i = 0; i < keys.length - 1; i++) {
            current = (Map<String, Object>) current.get(keys[i]);
            if (current == null) return null;
        }
        
        return current.get(keys[keys.length - 1]);
    }
}